#include "Light.h"

	void Light::SetPositionalLight(Vec3f Position)
	{
		//m_pos=(Position.X,Position.Y,Position.Z,1);
		m_pos=Position;
		m_lightType=1;
	}
	void Light::SetDirectionalLight(Vec3f TheDirection)
	{
		//Note by making the w co-ordinate = to 0 this creates a direction not a position for the light
		m_pos = TheDirection; //(TheDirection.X,TheDirection.Y,TheDirection.Z,0);
		m_lightType=0;
	}

	void Light::SetSpotLight(Vec3f Pos, Vec3f Direction, float Angle)
	{
		m_pos = Pos;
		//m_pos = (Pos.X,Pos.Y,Pos.Z,1);
		m_dir= Direction;
		m_angle = Angle;	
		m_lightType=2;
	}

	void Light::SetAmbient(float R,float G, float B, float A)
	{
		m_amb.X=R,m_amb.Y=G,m_amb.Z=B;
		m_ambA = A;
	}

	void Light::SetDiffuse(float R,float G, float B, float A)
	{
		m_dif.X=R,m_dif.Y=G,m_dif.Z=B;
		m_difA = A;
	}

	void Light::SetSpecular(float R,float G, float B, float A)
	{
		m_spe.X=R,m_spe.Y=G,m_spe.Z=B;
		m_speA = A;
	}

	void Light::LightOn()
	{
		//pg 216 gl
		//Sets the colours
		GLfloat TheAmb []= {m_amb.X,m_amb.Y,m_amb.Z,m_ambA};
		glLightfv(m_id,GL_AMBIENT,TheAmb);
	
		GLfloat TheDif []= {m_dif.X,m_dif.Y,m_dif.Z,m_difA};
		glLightfv(m_id,GL_DIFFUSE,TheDif);
	
		GLfloat TheSpe []= {m_spe.X,m_spe.Y,m_spe.Z,m_speA};	
		glLightfv(m_id,GL_SPECULAR,TheSpe);
	
	//Sets the position or direction
		if(m_lightType==0)
		{
		GLfloat ThePos [] = {m_pos.X,m_pos.Y,m_pos.Z,0};
		glLightfv(m_id, GL_POSITION, ThePos);
		}
		if(m_lightType==1)
		{
		GLfloat ThePos [] = {m_pos.X,m_pos.Y,m_pos.Z,1};
		glLightfv(m_id, GL_POSITION, ThePos);
		}
	if(m_lightType==2)
		{
		glLightf(m_id,GL_SPOT_CUTOFF, m_angle);
		GLfloat TheDir [] = {m_dir.X,m_dir.Y,m_dir.Z};
		glLightfv(m_id, GL_SPOT_DIRECTION,TheDir);
		}
	}

	void Light::MoveLight(Vec3f Pos)
	{
		m_pos =Pos;
	}

	void Light::LightOff()
	{}